
#include "message.h"
#include "params.h"
#include "stopcond.h"
#include "nnengine.h"
#include <ctime>

using namespace std;

int main (int argc, char** argv) {
	Message		*message;
	Parameters 	*params;
	
	// clock begin:
	struct timespec start;
	struct timespec stop;
	double elapsed;
	clock_gettime(CLOCK_REALTIME, &start);
		
	message = new Message();
	params  = new Parameters(message);

	message->showWelcome();
	
	params->analyseComandLine(argc, argv);
	
	if (params->hasErrors())
		message->showUsage();
	
	NeuralNetworkEngine* nn = new NeuralNetworkEngine(params, message);
	
	if (params->mustCompress())
		nn->transformBMPintoNGF();
	
	if (params->mustDecompress())
		nn->transformNDFintoBMP();
	
	if (nn->hasErrors())
		message->printMessage("Errors were encountered. Exiting.\n");
	
	delete nn;
	delete params;
	delete message;
	
	// clock finish:
	clock_gettime(CLOCK_REALTIME, &stop);
	elapsed=(double)(stop.tv_sec-start.tv_sec)+(double)(stop.tv_nsec-start.tv_nsec)/1e9;
	message->printMessage("Time elapsed: ");
	message->printMessage(elapsed);
	message->printMessage(".\n");

	return 0;
	
}
